package ptij.ADSL.common;

import ptij.domains.util.BF;

public class MuxDataFrame {
  
    public MuxDataFrame(int nbAS0, int nbAS1, int nbAS2, int nbAS3, 
        int nbLS0, int nbLS1, int nbLS2) {
  
        _fastByte = 0;
        _AS0 = new int[nbAS0];
        _AS1 = new int[nbAS1];
        _AS2 = new int[nbAS2];
        _AS3 = new int[nbAS3];
        _LS0 = new int[nbLS0];
        _LS1 = new int[nbLS1];
        _LS2 = new int[nbLS2];
      
        _AEXcond = (nbAS0 != 0) || (nbAS1 != 0) || (nbAS2 != 0) || (nbAS3 != 0);
	_AEX = 0;
	
	_LEXcond = _AEXcond || (nbLS0 != 0) || (nbLS1 != 0) || (nbLS2 != 0);
	_LEX = 0;	
    }
     
    // Fast byte 
    public void setFastByte(int b) {
        _fastByte = b;
    }
  
    public int getFastByte() {
        return _fastByte;
    }
  
    // AS0 Channel
    public void setAS0Byte(int b, int nb) {
        _AS0[nb] = b;
    } 
  
    public int getAS0Byte(int nb) {
        return _AS0[nb];
    }
    
    public int [] getAS0() {
        return _AS0;
    }

    // AS1 Channel  
    public void setAS1Byte(int b, int nb) {
        _AS1[nb] = b;
    }
  
    public int getAS1Byte(int nb) {
        return _AS1[nb];
    }

    public int [] getAS1() {
        return _AS1;
    }

    // AS2 Channel
    public void setAS2Byte(int b, int nb) {
        _AS2[nb] = b;
    }
  
    public int getAS2Byte(int nb) {
        return _AS2[nb];
    }

    public int [] getAS2() {
        return _AS2;
    }

    // AS3 Channel
    public void setAS3Byte(int b, int nb) {
        _AS3[nb] = b;
    }
  
    public int getAS3Byte(int nb) {
        return _AS3[nb];
    }

    public int [] getAS3() {
        return _AS3;
    }

    // LS0 Channel
    public void setLS0Byte(int b, int nb) {
        _LS0[nb] = b;
    }
  
    public int getLS0Byte(int nb) {
        return _LS0[nb];
    }

    public int [] getLS0() {
        return _LS0;
    }

    // LS1 Channel
    public void setLS1Byte(int b, int nb) {
        _LS1[nb] = b;
    }
  
    public int getLS1Byte(int nb) {
        return _LS1[nb];
    }

    public int [] getLS1() {
        return _LS1;
    }

    // LS3 Channel
    public void setLS2Byte(int b, int nb) {
        _LS2[nb] = b;
    }
  
    public int getLS2Byte(int nb) {
        return _LS2[nb];
    }

    public int [] getLS2() {
        return _LS2;
    }
  
    public void setAEXByte(int b) {
        _AEX = b;
    }
    
    public int getAEXByte() {
        return _AEX;
    }
    
    public boolean hasAEX() {
        return _AEXcond;
    }
    
    public void setLEXByte(int b) {
        _LEX = b;
    }
    
    public int getLEXByte() {
        return _LEX;
    }
    
    public boolean hasLEX() {
        return _LEXcond;
    }
    
    public int [] getAsArray() {    
        int size = 1 + _AS0.length + _AS1.length + _AS2.length + _AS3.length +
	    _LS0.length + _LS1.length + _LS2.length;
	
	if(_AEXcond) size++;
	if(_LEXcond) size++;
	    
        int ret[] = new int[size];	    
	ret[0] = _fastByte;

	int k = 1;
	for(int i = 0;i < _AS0.length;i++) {
	    ret[k] = _AS0[i];
	    k++;
	}
	for(int i = 0;i < _AS1.length;i++) {
	    ret[k] = _AS1[i];
	    k++;
	}
	for(int i = 0;i < _AS2.length;i++) {
	    ret[k] = _AS2[i];
	    k++;
	}
	for(int i = 0;i < _AS3.length;i++) {
	    ret[k] = _AS3[i];
	    k++;
	}
	for(int i = 0;i < _LS0.length;i++) {
	    ret[k] = _LS0[i];
	    k++;
	}
	for(int i = 0;i < _LS1.length;i++) {
	    ret[k] = _LS1[i];
	    k++;
	}
	for(int i = 0;i < _LS2.length;i++) {
	    ret[k] = _LS2[i];
	    k++;
	}
	if(_AEXcond) {
	    ret[k] = _AEX;
	    k++;
	}
	if(_LEXcond) {
	    ret[k] = _LEX;
	    k++;
	}
	
	return ret;    
    }
  
    public void print() {
        System.out.println("First byte = " +  BF.byteToHex((byte) _fastByte));
	int j;	

	if(_AS0.length != 0) {
	    System.out.println("Bearer Channel AS0 (" + _AS0.length + "): ");
	    for(j = 0;j < _AS0.length - 1;j++)
	        System.out.print(BF.byteToHex((byte)_AS0[j]) + " ");
	    System.out.println(BF.byteToHex((byte)_AS0[j]));
	}

	if(_AS1.length != 0) {
	    System.out.println("Bearer Channel AS1 (" + _AS1.length + "): ");
	    for(j = 0;j < _AS1.length - 1;j++)
	        System.out.print(BF.byteToHex((byte)_AS1[j]) + " ");
	    System.out.println(BF.byteToHex((byte)_AS1[j]));
	}

	if(_AS2.length != 0) {
	    System.out.println("Bearer Channel AS2 (" + _AS2.length + "): ");
	    for(j = 0;j < _AS2.length - 1;j++)
	        System.out.print(BF.byteToHex((byte)_AS2[j]) + " ");
	    System.out.println(BF.byteToHex((byte)_AS2[j]));
	}

	if(_AS3.length != 0) {
	    System.out.println("Bearer Channel AS3 (" + _AS3.length + "): ");
	    for(j = 0;j < _AS3.length - 1;j++)
	        System.out.print(BF.byteToHex((byte)_AS3[j]) + " ");
	    System.out.println(BF.byteToHex((byte)_AS3[j]));
	}
	
	if(_LS0.length != 0) {
	    System.out.println("Bearer Channel LS0 (" + _LS0.length + "): ");
	    if(_LS0.length != 0) {
	        for(j = 0;j < _LS0.length - 1;j++)
		    System.out.print(BF.byteToHex((byte)_LS0[j]) + " ");
		System.out.println(BF.byteToHex((byte)_LS0[j]));
	    }
        }

	if(_LS1.length != 0) {
	    System.out.println("Bearer Channel LS1 (" + _LS1.length + "): ");
	    if(_LS1.length != 0) {
	        for(j = 0;j < _LS1.length - 1;j++)
		    System.out.print(BF.byteToHex((byte)_LS1[j]) + " ");
		System.out.println(BF.byteToHex((byte)_LS1[j]));
	    }
        }

	if(_LS2.length != 0) {
	    System.out.println("Bearer Channel LS2 (" + _LS2.length + "): ");
	    if(_LS2.length != 0) {
	        for(j = 0;j < _LS2.length - 1;j++)
		    System.out.print(BF.byteToHex((byte)_LS2[j]) + " ");
		System.out.println(BF.byteToHex((byte)_LS2[j]));
	    }
        }
	if(_AEXcond) {
	    System.out.println("AEX Byte = " + BF.byteToHex((byte)_AEX));
	}
	if(_LEXcond) {
	    System.out.println("LEX Byte = " + BF.byteToHex((byte)_LEX));
	}
  }
  
  public String toString() {
       StringBuffer buf = new 
           StringBuffer("First byte = " +  BF.byteToHex((byte) _fastByte));
        int j;	

	if(_AS0.length != 0) {
	    buf.append("Bearer Channel AS0 (" + _AS0.length + "): ");
	    for(j = 0;j < _AS0.length - 1;j++)
	        buf.append(BF.byteToHex((byte)_AS0[j]) + " ");
	    buf.append(BF.byteToHex((byte)_AS0[j]));
	}

	if(_AS1.length != 0) {
	    buf.append("Bearer Channel AS1 (" + _AS1.length + "): ");
	    for(j = 0;j < _AS1.length - 1;j++)
	        buf.append(BF.byteToHex((byte)_AS1[j]) + " ");
	    buf.append(BF.byteToHex((byte)_AS1[j]));
	}

	if(_AS2.length != 0) {
	    buf.append("Bearer Channel AS2 (" + _AS2.length + "): ");
	    for(j = 0;j < _AS2.length - 1;j++)
	        buf.append(BF.byteToHex((byte)_AS2[j]) + " ");
	    buf.append(BF.byteToHex((byte)_AS2[j]));
	}

	if(_AS3.length != 0) {
	    buf.append("Bearer Channel AS3 (" + _AS3.length + "): ");
	    for(j = 0;j < _AS3.length - 1;j++)
	        buf.append(BF.byteToHex((byte)_AS3[j]) + " ");
	    buf.append(BF.byteToHex((byte)_AS3[j]));
	}
	
	if(_LS0.length != 0) {
	    buf.append("Bearer Channel LS0 (" + _LS0.length + "): ");
	    if(_LS0.length != 0) {
	        for(j = 0;j < _LS0.length - 1;j++)
		    buf.append(BF.byteToHex((byte)_LS0[j]) + " ");
		buf.append(BF.byteToHex((byte)_LS0[j]));
	    }
        }

	if(_LS1.length != 0) {
	    buf.append("Bearer Channel LS1 (" + _LS1.length + "): ");
	    if(_LS1.length != 0) {
	        for(j = 0;j < _LS1.length - 1;j++)
		    buf.append(BF.byteToHex((byte)_LS1[j]) + " ");
		buf.append(BF.byteToHex((byte)_LS1[j]));
	    }
        }

	if(_LS2.length != 0) {
	    buf.append("Bearer Channel LS2 (" + _LS2.length + "): ");
	    if(_LS2.length != 0) {
	        for(j = 0;j < _LS2.length - 1;j++)
		    buf.append(BF.byteToHex((byte)_LS2[j]) + " ");
		buf.append(BF.byteToHex((byte)_LS2[j]));
	    }
        }
	if(_AEXcond) {
	    buf.append("AEX Byte = " + BF.byteToHex((byte)_AEX));
	}
	if(_LEXcond) {
	    buf.append("LEX Byte = " + BF.byteToHex((byte)_LEX));
	}         
        return buf.toString();
  }
  
  protected int _fastByte;
  protected int _AS0[];
  protected int _AS1[];
  protected int _AS2[];
  protected int _AS3[];
  protected int _LS0[];
  protected int _LS1[];
  protected int _LS2[];
  protected int _AEX;
  protected int _LEX;
  protected boolean _AEXcond;
  protected boolean _LEXcond;
}
